/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DialogTrataErro.java
 *
 * Created on 16/05/2011, 17:10:40
 */
package br.jcrsistemas.util;

/**
 *
 * @author Kadu
 */
public class DialogTrataErro extends javax.swing.JDialog {
    Exception exception;

    /** Creates new form DialogTrataErro */
    public DialogTrataErro(java.awt.Frame parent, boolean modal, SysException e) {

    }

    public DialogTrataErro(java.awt.Frame parent, boolean modal, Exception e) {
        super(parent, modal);
        exception = e;
        initComponents();
        if(Util.isConectadoInternet()) {
            btnEnviarRelat.setVisible(true);
        }
        else {
            btnEnviarRelat.setVisible(false);
        }
        setTitle("Erro: " + exception.getMessage());
        lblErro.setText("Erro..: " + exception.getMessage() );
        StringBuilder sb = new StringBuilder();
        for(StackTraceElement st: exception.getStackTrace()) {
            sb.append(st.toString()).append("\n");
        }
        txtErro.setText(sb.toString());
        setSize(txtErro.getWidth(), getHeight());
        repaint();
        setLocationRelativeTo(null);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lblErro = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtErro = new javax.swing.JTextArea();
        btnEnviarRelat = new javax.swing.JButton();
        btnOk = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Erro:");

        lblErro.setFont(new java.awt.Font("Segoe UI", 1, 18));
        lblErro.setText("Erro:");

        txtErro.setColumns(20);
        txtErro.setEditable(false);
        txtErro.setRows(5);
        jScrollPane1.setViewportView(txtErro);

        btnEnviarRelat.setMnemonic('E');
        btnEnviarRelat.setText("Enviar relatório de erros");

        btnOk.setText("OK");
        btnOk.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnOkActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 988, Short.MAX_VALUE)
                    .addComponent(lblErro)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btnEnviarRelat)
                        .addGap(18, 18, 18)
                        .addComponent(btnOk)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblErro)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 402, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnEnviarRelat)
                    .addComponent(btnOk))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOkActionPerformed
        dispose();
    }//GEN-LAST:event_btnOkActionPerformed

    /**
     * @param args the command line arguments
     */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnEnviarRelat;
    private javax.swing.JButton btnOk;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblErro;
    private javax.swing.JTextArea txtErro;
    // End of variables declaration//GEN-END:variables
}
